package com.ridu.project.beshid.controller;

import com.ridu.project.beshid.api.GeneralResponse;
import com.ridu.project.beshid.api.Status;
import com.ridu.project.beshid.service.JifenReqService;
import com.ridu.project.beshid.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by user on 2018/5/22.
 */
@Controller
@RequestMapping(value = "jifenReq",produces = "application/json")
@Slf4j
public class JifenReqController extends BaseController {

    @Autowired
    private JifenReqService service;
    @Autowired
    private UserService userService;

    @RequestMapping(value = "toJifenSentList")
    public String redirectSys() {
        return "jifen_admin_audit";
    }

    @RequestMapping(value = "toJifenRecordList")
    public String toJifenRecordList() {
        return "jifen_admin_audit_record";
    }

    /**
     * 获取积分
     * @return
     */
    @RequestMapping(value = "getJifenAuditList")
    @ResponseBody
    public GeneralResponse getJifenAuditList(@RequestParam int currentPage, @RequestParam int pageSize){
        GeneralResponse response = new GeneralResponse();
        try {
            return service.getJifensAuditList(currentPage, pageSize, null);
        } catch (Exception e) {
            response.setStatus(Status.FAILED);
            response.setMessage(e.getMessage());
        }
        return response;
    }

    /**
     * 获取积分
     * @return
     */
    @RequestMapping(value = "getJifenRecordList")
    @ResponseBody
    public GeneralResponse getJifenRecordList(@RequestParam int currentPage, @RequestParam int pageSize,
                                              String startTime, String endTime, String username,String platform){
        GeneralResponse response = new GeneralResponse();
        try {
            return service.getJifensAuditList(currentPage, pageSize, startTime, endTime, username, platform, "ALL");
        } catch (Exception e) {
            response.setStatus(Status.FAILED);
            response.setMessage(e.getMessage());
        }
        return response;
    }

    /**
     * 获取积分
     * @return
     */
    @RequestMapping(value = "sent", method= RequestMethod.POST)
    @ResponseBody
    public GeneralResponse jifenSent(@RequestParam String ids){
        GeneralResponse response = new GeneralResponse();
        try {
            return service.sent(ids);
        } catch (Exception e) {
            response.setStatus(Status.FAILED);
            response.setMessage(e.getMessage());
        }
        return response;
    }

}
